<template>
  <div class="dashboard">
    <div class="dashboard-header">
      <h2>仪表盘</h2>
      <p>欢迎回来，{{ userStore.user?.username }}！</p>
    </div>
    
    <!-- 统计卡片 -->
    <a-row :gutter="24" class="stats-row">
      <a-col :xs="24" :sm="12" :lg="6">
        <a-card class="stat-card">
          <a-statistic
            title="总用户数"
            :value="stats.totalUsers"
            :value-style="{ color: '#3f8600' }"
          >
            <template #prefix>
              <UserOutlined />
            </template>
          </a-statistic>
        </a-card>
      </a-col>
      
      <a-col :xs="24" :sm="12" :lg="6">
        <a-card class="stat-card">
          <a-statistic
            title="今日访问"
            :value="stats.todayVisits"
            :value-style="{ color: '#1890ff' }"
          >
            <template #prefix>
              <EyeOutlined />
            </template>
          </a-statistic>
        </a-card>
      </a-col>
      
      <a-col :xs="24" :sm="12" :lg="6">
        <a-card class="stat-card">
          <a-statistic
            title="总订单"
            :value="stats.totalOrders"
            :value-style="{ color: '#cf1322' }"
          >
            <template #prefix>
              <ShoppingOutlined />
            </template>
          </a-statistic>
        </a-card>
      </a-col>
      
      <a-col :xs="24" :sm="12" :lg="6">
        <a-card class="stat-card">
          <a-statistic
            title="总收入"
            :value="stats.totalRevenue"
            :precision="2"
            prefix="¥"
            :value-style="{ color: '#722ed1' }"
          >
            <template #prefix>
              <DollarOutlined />
            </template>
          </a-statistic>
        </a-card>
      </a-col>
    </a-row>
    
    <!-- 图表和其他内容 -->
    <a-row :gutter="24" class="content-row">
      <a-col :xs="24" :lg="16">
        <a-card title="访问趋势" class="chart-card">
          <div class="chart-placeholder">
            <p>这里可以集成Chart.js或ECharts图表</p>
          </div>
        </a-card>
      </a-col>
      
      <a-col :xs="24" :lg="8">
        <a-card title="快速操作" class="quick-actions">
          <a-space direction="vertical" style="width: 100%">
            <a-button type="primary" block @click="$router.push('/system/user')">
              <UserAddOutlined />
              添加用户
            </a-button>
            <a-button block @click="$router.push('/system/role')">
              <TeamOutlined />
              角色管理
            </a-button>
            <a-button block @click="$router.push('/system/permission')">
              <SafetyOutlined />
              权限设置
            </a-button>
          </a-space>
        </a-card>
        
        <a-card title="组件演示" class="component-demo" style="margin-top: 16px;">
          <div class="demo-section">
            <h4>星级评分组件</h4>
            <StarRating
              v-model:value="rating"
              :max="5"
              allow-half
              show-text
              @change="handleRatingChange"
            />
            <p>当前评分：{{ rating }}</p>
          </div>
          
          <div class="demo-section">
            <h4>模态框组件</h4>
            <a-button type="primary" @click="showModal = true">
              打开模态框
            </a-button>
            
            <EnterpriseModal
              v-model:open="showModal"
              title="演示模态框"
              @ok="handleModalOk"
              @cancel="handleModalCancel"
            >
              <p>这是一个可复用的企业级模态框组件</p>
              <p>支持自定义标题、宽度、按钮文字等属性</p>
            </EnterpriseModal>
          </div>
        </a-card>
      </a-col>
    </a-row>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import {
  UserOutlined,
  EyeOutlined,
  ShoppingOutlined,
  DollarOutlined,
  UserAddOutlined,
  TeamOutlined,
  SafetyOutlined
} from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { useUserStore } from '@/stores/user'
import { StarRating, EnterpriseModal } from '@/components'

const userStore = useUserStore()

// 统计数据
const stats = reactive({
  totalUsers: 1234,
  todayVisits: 8765,
  totalOrders: 543,
  totalRevenue: 98765.43
})

// 演示数据
const rating = ref(4.5)
const showModal = ref(false)

const handleRatingChange = (value: number) => {
  message.success(`评分已更改为：${value}`)
}

const handleModalOk = () => {
  message.success('模态框确认操作')
  showModal.value = false
}

const handleModalCancel = () => {
  message.info('模态框取消操作')
}

onMounted(() => {
  // 这里可以加载仪表盘数据
  console.log('Dashboard mounted')
})
</script>

<style scoped>
.dashboard {
  padding: 0;
}

.dashboard-header {
  margin-bottom: 24px;
}

.dashboard-header h2 {
  margin: 0 0 8px 0;
  color: #262626;
}

.dashboard-header p {
  margin: 0;
  color: #8c8c8c;
}

.stats-row {
  margin-bottom: 24px;
}

.stat-card {
  text-align: center;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.content-row {
  margin-bottom: 24px;
}

.chart-card {
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chart-placeholder {
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  border-radius: 4px;
  color: #8c8c8c;
}

.quick-actions,
.component-demo {
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.demo-section {
  margin-bottom: 16px;
  padding: 16px;
  background: #fafafa;
  border-radius: 4px;
}

.demo-section:last-child {
  margin-bottom: 0;
}

.demo-section h4 {
  margin: 0 0 12px 0;
  color: #262626;
}

:deep(.ant-statistic-title) {
  font-size: 14px;
  color: #8c8c8c;
}

:deep(.ant-statistic-content) {
  font-size: 24px;
  font-weight: 600;
}
</style> 